package com.dmjy.pub.export.data2csv.controller;

import cn.hutool.core.io.FileUtil;
import com.dmjy.pub.export.data2csv.model.PO.ExportAppUserPO;
import com.dmjy.pub.export.data2csv.service.ExportDataService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;

/**
 * @author 敖癸
 * @formatter:on
 * @since 2024/3/7
 */
@Slf4j
@RestController
@RequiredArgsConstructor
public class ExportController {

    private final ExportDataService exportDataService;

    @PostMapping("/export/db2csv")
    public void exportAppUserData(@RequestBody ExportAppUserPO po) {
        File file = FileUtil.newFile(po.getFile() + ".ing");
        exportDataService.exportDataToFile(po.getSql(), file);
    }

}
